package com.java.demo.java;

/**
 * 内部类
 *
 * @auther zhangwj
 * @date 2020/12/3 上午10:35
 */
public class InnerClass {

    static {
        System.out.println("InnerClass开始实例化");
    }
    private int age = 10;

    public String name = "外部类名称";

    void out() {
        class MethodInnerClass{

            void out(){
                System.out.println(InnerClass.this.name);
            }
        }
        System.out.println(name);

    }

    class MyInnerClass {

        {
            System.out.println("MyInnerClass开始实例化");
        }

        private String name = "内部类名称";

        void out(String name) {
            System.out.println("我是内部类+" + age + name + InnerClass.this.name);
        }
    }
}

class Main {

    public static void main(String[] args) {
        InnerClass innerClass = new InnerClass();

        InnerClass.MyInnerClass myInnerClass = innerClass.new MyInnerClass();
        myInnerClass.out(innerClass.name);
    }
}
